//
//  Gargoygle.m
//  TowerDefence
//
//  Created by k3 on 6/6/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "Gargoygle.h"
#import "PlayScreen.h"
#import "iCoreGUIController.h"

@implementation Gargoygle
-(id)initGargoygleWith:(PlayScreen*)_playScreen withRoad:(NSMutableArray*)_road{
    self=[super initEnemyWith:_playScreen];
    armor=2;
    HP=50;
    speed=1.0f;
    spriteBody=[[CCSprite alloc]initWithSpriteFrameName:@"Gargoygle_Fly_01.png"];
    road = _road;
    damage = 15;
    moneyOnDie = 30;
    nextHeadingPoint=1;
    fly=YES;
    [self drawBloodMeterWithLength:spriteBody.contentSize.width/2 + 10 width:3 position:ccp(spriteBody.contentSize.width/2, spriteBody.contentSize.height)];
    return self;
}

-(void)moveOnTheRoad {
    [super moveOnTheRoad];
    
    /*if(!handler.mainGUIController.isMuteSound) {
        [audioPlayer playWithFileName:AUDIO_FLY_MONSTER loop:NO];
    }*/
}

-(void)animationMoveLeft{
    //NSLog(@"Running");
    [super animationMoveLeft];
    CCAnimation *animation = [self loadAnimationFromCacheByName:@"Gargoygle_Fly" withCount:7 delay:0.08];
    [spriteBody runAction:[CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:animation]]];
}

-(void)animationMoveUp{
    [super animationMoveUp];
    CCAnimation *animation = [self loadAnimationFromCacheByName:@"Gargoygle_Fly_Up" withCount:7 delay:0.1];
    [spriteBody runAction:[CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:animation]]];
}

-(void)animationMoveDown{
    [super animationMoveDown];
    CCAnimation *animation = [self loadAnimationFromCacheByName:@"Gargoygle_Fly_Down" withCount:7 delay:0.1];
    [spriteBody runAction:[CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:animation]]];
}

-(void)animationDie{
    [super animationDie];
    CCAnimation *animation = [self loadAnimationFromCacheByName:@"Gargoygle_Die" withCount:6 delay:0.1];
    CCCallFunc *dieCallBack = [CCCallFunc actionWithTarget:self selector:@selector(dieCallBack)];
    [spriteBody runAction:[CCSequence actions:[CCAnimate actionWithAnimation:animation restoreOriginalFrame:NO],[CCDelayTime actionWithDuration:0.75f], dieCallBack, nil]];
    
    if(!handler.mainGUIController.isMuteSound) {
        [handler.mainGUIController playEffect:AUDIO_GARGORYGLE];
    }
}

-(void)dealloc {
    NSLog(@"Goblin dealoc");
    [self removeAnimationInFrameCache:@"Gargoygle_Fly"];
    [self removeAnimationInFrameCache:@"Gargoygle_Fly_Up"];
    [self removeAnimationInFrameCache:@"Gargoygle_Fly_Down"];
    [self removeAnimationInFrameCache:@"Gargoygle_Die"];
    [super dealloc];
}

@end
